package com.yy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yy.domain.ProdComm;
import com.yy.dto.PageDTO;
import com.yy.dto.ProdCommQueryDTO;
import com.yy.service.ProdCommService;
import com.yy.mapper.ProdCommMapper;
import com.yy.utils.AuthUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

/**
* @author yy5
* @description 针对表【prod_comm(商品评论)】的数据库操作Service实现
* @createDate 2023-11-27 20:47:04
*/
@Service
public class ProdCommServiceImpl extends ServiceImpl<ProdCommMapper, ProdComm>
    implements ProdCommService{

    @Autowired
    private ProdCommMapper prodCommMapper;
    /**
     * 分页查询所有评论
     *
     * @param pageDTO
     * @param prodCommQueryDTO
     * @return
     */
    @Override
    public Page<ProdComm> loadProdCommPage(PageDTO pageDTO, ProdCommQueryDTO prodCommQueryDTO) {
        Long shopId= AuthUtil.getShopId();
        Page<ProdComm> page=new Page<>(pageDTO.getCurrent(),pageDTO.getSize());
        return this.prodCommMapper.selectPage(page,new LambdaQueryWrapper<ProdComm>()
                .eq(!ObjectUtils.isEmpty(prodCommQueryDTO.getStatus()),ProdComm::getStatus,prodCommQueryDTO.getStatus())
                .eq(!shopId.equals(1L),ProdComm::getShopId,shopId)
                .like(StringUtils.hasText(prodCommQueryDTO.getProdName()),ProdComm::getProdName,prodCommQueryDTO.getProdName())
                .orderByDesc(ProdComm::getCreateTime)
        );
    }
}




